home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 11.6 KB | 368 lines | [TEXT/MPS ] |
- // UOSAScript.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UOSASCRIPT__
- #define __UOSASCRIPT__
-
- // MacApp
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- // Toolbox
-
- #ifndef __COMPONENTS__
- #include <Components.h>
- #endif
-
- #ifndef __OSA__
- #include <OSA.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class CAEDesc;
- class TAppleEvent;
- class TOSAScriptRep;
- class TFile;
-
- //========================================================================================
- // COSAScript: Object representation of an OSA Script.
- //========================================================================================
-
- class COSAScript
- {
- protected:
- static ComponentInstance fgGenericScriptingComponent;
- static COSAScript fgGlobalScript;
- static COSAScript fgSharedScript;
- static COSAScript fgEmptyScript;
-
- public:
- static ComponentInstance GetDefaultComponent();
-
- static COSAScript GetEmptyScript();
-
- inline static COSAScript GetGlobalScript();
- inline static void SetGlobalScript(OSAID globalScript);
-
- inline static COSAScript GetSharedScript();
- inline static void SetSharedScript(OSAID sharedScript);
-
- public:
- OSAID fScriptID;
-
- COSAScript();
- COSAScript(OSAID theScript);
-
- operator OSAID() const { return fScriptID; }
- operator OSAID*() { return &fScriptID; }
-
- OSAID operator=(OSAID theScript) { fScriptID = theScript; return fScriptID; }
-
- Boolean IsEmpty();
-
- OSAError Execute(ComponentInstance theComponent, OSAID theContext, long executeFlags, OSAID& theResult);
- OSAError GetScript(ComponentInstance theComponent, DescType whichType, CAEDesc& scriptDesc, long storeFlags);
- OSAError SetScript(ComponentInstance theComponent, const CAEDesc& scriptDesc, long compileFlags, long loadFlags);
- OSAError DisposeScript(ComponentInstance theComponent);
- OSAError SetParentScript(ComponentInstance genericComponent, OSAID itsParent);
- OSAError GetParentScript(ComponentInstance genericComponent, OSAID& itsParent);
- OSAError DoOSAEvent(ComponentInstance theComponent, TAppleEvent* message, TAppleEvent* reply, long modeFlags);
- };
-
- //----------------------------------------------------------------------------------------
- // COSAScript inlines
- //----------------------------------------------------------------------------------------
-
- inline COSAScript COSAScript::GetGlobalScript()
- {
- return COSAScript::fgGlobalScript;
- }
-
- inline void COSAScript::SetGlobalScript(OSAID globalScript)
- {
- COSAScript::fgGlobalScript = globalScript;
- }
-
- inline COSAScript COSAScript::GetSharedScript()
- {
- return COSAScript::fgSharedScript;
- }
-
- inline void COSAScript::SetSharedScript(OSAID sharedScript)
- {
- COSAScript::fgSharedScript = sharedScript;
- }
-
- //========================================================================================
- // CLASS COSAScriptCntPtr
- //========================================================================================
-
- class COSAScriptCntPtr
- {
- //----------------------------------------------------------------------------------------
- // Static members
- //----------------------------------------------------------------------------------------
-
- public:
- static TOSAScriptRep* NewOSAScript();
-
- public:
- COSAScriptCntPtr();
- // Creates a "NULL" pointer.
-
- virtual ~COSAScriptCntPtr();
- // Destroy the pointer.
- // Decrements the count in the rep, and deletes the rep if count is zero.
-
- COSAScriptCntPtr(const COSAScriptCntPtr& other);
- // FW_SPlatformPoint this pointer to the same rep as the other pointer points to.
-
- COSAScriptCntPtr(TOSAScriptRep* rep);
- // Creates a pointer pointing at rep.
-
- COSAScriptCntPtr& operator=(const COSAScriptCntPtr& other);
- // Assignment, point this ponter to the same rep as the other pointer points to.
-
- COSAScriptCntPtr& operator=(TOSAScriptRep* rep);
- // Assignment, point this ponter to rep.
-
- TOSAScriptRep* operator->() const; // Must be overlodded by subclass
- // Provide access to members of rep.
-
- TOSAScriptRep& operator*() const;
- // Provide access to rep.
- // This operator should be used only if operator->() is not sufficient.
-
- Boolean operator==(const COSAScriptCntPtr& other) const;
- // Points to the same representation object?
-
- Boolean operator!=(const COSAScriptCntPtr& other) const;
- // Points to a different representation object?
-
- operator const void*() const;
- // Use to test if this is a "NULL" pointer.
-
- protected:
- void SetRep(TOSAScriptRep* rep);
-
- void UpCount();
- // Implementation method, increment the reference count in rep.
-
- void DownCount();
- // Implementation method, decrement the reference count in rep.
- // Deletes rep if reference count is zero.
-
- TOSAScriptRep *fRep;
- };
-
- //----------------------------------------------------------------------------------------
- // COSAScriptCntPtr::operator->
- //----------------------------------------------------------------------------------------
-
- inline TOSAScriptRep* COSAScriptCntPtr::operator->() const
- {
- return fRep;
- }
-
- //----------------------------------------------------------------------------------------
- // COSAScriptCntPtr::operator*
- //----------------------------------------------------------------------------------------
-
- inline TOSAScriptRep& COSAScriptCntPtr::operator*() const
- {
- return *fRep;
- }
-
- //----------------------------------------------------------------------------------------
- // COSAScriptCntPtr::operator==
- //----------------------------------------------------------------------------------------
-
- inline Boolean COSAScriptCntPtr::operator==(const COSAScriptCntPtr& other) const
- {
- return (fRep == other.fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // COSAScriptCntPtr::operator!=
- //----------------------------------------------------------------------------------------
-
- inline Boolean COSAScriptCntPtr::operator!=(const COSAScriptCntPtr& other) const
- {
- return !operator==(other);
- }
-
- //----------------------------------------------------------------------------------------
- // COSAScriptCntPtr::operator const void*
- //----------------------------------------------------------------------------------------
-
- inline COSAScriptCntPtr::operator const void*() const
- {
- return (const void*) fRep;
- }
-
- //========================================================================================
- // TOSAScriptRep: MacApp Object representation of an OSA Script.
- //========================================================================================
-
- class TOSAScriptRep : public TObject
- {
- MA_DECLARE_CLASS;
-
- //----------------------------------------------------------------------------------------
- // Instance data
- //----------------------------------------------------------------------------------------
-
- public:
- COSAScript fScript; // the script
- long fNextScriptIdle; // when to next give idle time to attached scripts
- long fLoadFlags; // Flags for OSALoad
- long fCompileFlags; // Flags for OSACompile
- long fStoreFlags; // Flags for OSAStore
- long fExecuteFlags; // Flags for OSAExecute
- long fDoEventFlags; // Flags for OSADoEvent
- ComponentInstance fScriptingComponent; // the scripting component for this script
-
- //----------------------------------------------------------------------------------------
- // Construction
- //----------------------------------------------------------------------------------------
-
- public:
-
- TOSAScriptRep();
- virtual ~TOSAScriptRep();
-
- void IOSAScript();
-
- //----------------------------------------------------------------------------------------
- // Attached Scripts
- //----------------------------------------------------------------------------------------
-
- virtual Boolean HasOSAScript();
- // Return TRUE if this object has a script attached.
-
- virtual void FreeOSAScript();
- // Throws out the script attached to this object.
-
- // virtual ComponentInstance GetScriptingComponent();
- // // Returns an instance of the scripting component used with scripts
- // // attached to this object. Default is to return the Generic component.
-
- virtual void SetOSAScript(const CAEDesc& scriptDesc);
- // Attaches a script described in the scriptDesc
-
- virtual void GetOSAScript(CAEDesc& scriptDesc,
- const CAEDesc& desiredType);
- // Returns the script attached to this object as the desiredType.
-
- virtual OSAID ExecuteOSAScript();
- // Executes the attached script and returns the result.
-
- virtual Boolean HandleOSAEvent(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Gives an attached script a chance to handle an AppleEvent.
- // Returns TRUE if the script handled the event.
-
- virtual void IdleOSAScript();
- // Gives an attached script idle time so its idle event handler can do some work.
- // Respects the object's fNextScriptIdle so you can call it as often as you like.
-
- virtual OSAID GetOSAParent();
- // Returns this object's parent script. If the scripting component supports
- // inheritance the HandleOSAEvent method will use this parent script to
- // set up the inheritance chain.
- // The default parent script is TScriptEventDispatcher's shared handler script.
-
- virtual void ReadOSAScript(TStream* aStream);
- // Reads a script from a stream.
-
- virtual void ReadOSAScript(TFile* aFile,
- ResType resourceType,
- short resourceID);
- // Reads a script from a resource
-
- virtual void WriteOSAScript(TStream* aStream, DescType asType);
- // Writes a script to aStream.
-
- virtual void WriteOSAScript(TFile* aFile,
- DescType theType,
- short resourceID,
- CStr255& resourceName);
- // Writes an attached script to aStream.
-
- //----------------------------------------------------------------------------------------
- // Reference Counting Support - We need reference counting in order to prevent
- // premature death of a script while it is still being executed. This could
- // happen if the object to which the script is attached is killed off while
- // the script is being run (such as in an "on close" attached script).
- //----------------------------------------------------------------------------------------
-
- long IncrementReferenceCount();
- long DecrementReferenceCount();
-
- protected:
- unsigned long fRefCount;
- };
-
- //----------------------------------------------------------------------------------------
- // TOSAScriptRep inlines
- //----------------------------------------------------------------------------------------
-
- inline long TOSAScriptRep::DecrementReferenceCount()
- {
- return --fRefCount;
- }
-
- inline long TOSAScriptRep::IncrementReferenceCount()
- {
- return ++fRefCount;
- }
-
- //========================================================================================
- // TExecuteScriptCommand: Command to execute an OSA script.
- //========================================================================================
-
- class TExecuteScriptCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- COSAScript fScript;
- COSAScript fScriptContext;
- Boolean fDisposeScript;
- ComponentInstance fComponent;
- long fExecuteFlags;
-
- TExecuteScriptCommand();
- // Constructor
-
- void IExecuteScriptCommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify,
- OSAID scriptToExecute,
- OSAID theScriptContext,
- long executeFlags,
- Boolean disposeOfScript,
- ComponentInstance whichComponent);
-
- virtual void DoIt();
- // Executes the script
-
- virtual ~TExecuteScriptCommand();
-
- };
-
- #endif // __UOSASCRIPT__
-